package Classes.GameViews.ViewPanels
{
	import Classes.GameViews.ViewIcons.ViewIcon;
	import Classes.GameViews.ViewScenes.VS_Main;
	import Classes.Managers.M_Communication;
	import Classes.Managers.M_ConfigData;
	import Classes.staticinfo.Language;
	
	import UIComponents.FlatInfo;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.system.ApplicationDomain;

	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：May 9, 2012 4:03:20 PM 
	 */ 
	public class VP_DayRewardUI extends ViewPanel
	{
		private static var _instance:VP_DayRewardUI;
		private var _interfaceUI:Sprite;
		private var _isFensi:Boolean;
		public function VP_DayRewardUI()
		{
			this.init();
		}
		
		private function init():void
		{
			this._interfaceUI=new (ApplicationDomain.currentDomain.getDefinition("DayRewardUI") as Class);
			this.addChild(this._interfaceUI);
			this.addListener();
		}
		
		private function addListener():void
		{
			this.addEventListener("customCallBack",customHandler);
			this.addEventListener("addJs",addFensiFun);
		}
		
		private function customHandler(e:Event):void
		{
			//领取
			M_Communication.instance.send(127011);
		}
		
		private function addFensiFun(e:Event):void
		{
			//加为粉丝
			navigateToURL(new URLRequest(M_ConfigData.instance.addFansUrl));
		}
		
		public function closeHandler(e:Event):void
		{
			this.close();
			//打开 进游戏点击每日登录奖励后需弹出小镇日报的活动弹框
			VP_movement.instance.openPanel();
			
		}
		
		/**
		 * 打开文字提示普弹框
		 */	
		public function open(day:int):void
		{
			var arr:Array=this.getRewardArr();
			this.setData(arr,day);
			this.openAt(VS_Main.instance,true);
			this.toCenter();
		}
		
		/**
		 * 赋值 
		 * @param arr
		 * @param day
		 */		
		public function setData(arr:Array,day:int):void
		{
			this._interfaceUI["setRewardData"](arr,day,this.isFensi);
		}
		
		public static function get instance():VP_DayRewardUI
		{
			if(!_instance)_instance=new VP_DayRewardUI();
			return _instance;
		}
		
		public function get interfaceUI():Sprite
		{
			return _interfaceUI;
		}
		
		public function getRewardArr():Array
		{
			var arr:Array=new Array();
			var str:String=M_ConfigData.instance.dayRewardItems;
			
			var hkArr:Array=str.split(",");
			for(var i:int=0;i<hkArr.length;i++)
			{
				var obj:Object=new Object();
				var dhArr:Array=hkArr[i].toString().split("|");
				if(dhArr && dhArr.length>0)
				{
					obj.itemNum=dhArr[1];
					obj.icon=this.getSpectialIcon(dhArr[0],obj);
					arr.push(obj);
				}
			}
			return arr;
		}
		
		private function getSpectialIcon(id:Number,obj:Object):DisplayObject
		{
			var countPic:DisplayObject=null;
			//金币X100、1D生命值上限+1、1D人物行动速度+1、能量值+2  1|100,2|1,3|1,4|2
			switch(id)
			{
				case 1://金币
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_JB"});
					obj.displayViewIconName=Language.jb;
					break;
				case 2:
					countPic=new (ApplicationDomain.currentDomain.getDefinition("addLifeValue") as Class);
					obj.displayViewIconName=Language.everyDayLifeTips;
					break;
				case 3:
					countPic=new (ApplicationDomain.currentDomain.getDefinition("addSpeed") as Class);
					obj.displayViewIconName=Language.everyDaySpeedTips;
					break;
				case 4:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_Act"});
					obj.displayViewIconName=Language.act;
					break;
				case 5:
					countPic=new (ApplicationDomain.currentDomain.getDefinition("maxAction") as Class);
					obj.displayViewIconName=Language.maxAct;
					break;
			}
			if(countPic as ViewIcon)
			{
				(countPic as ViewIcon).iHeight=79;
				(countPic as ViewIcon).iWidth=79;
				(countPic as ViewIcon).setNumSpVisiable(false);
			}else{
				countPic.width=79;
				countPic.height=79;
			}
			return countPic;
		}

		/**
		 * 是否是粉丝 
		 */
		public function get isFensi():Boolean
		{
			return _isFensi;
		}

		/**
		 * @private
		 */
		public function set isFensi(value:Boolean):void
		{
			_isFensi = value;
			FlatInfo.isFensi=value;
		}

	}
}
